import {
  updateEnableSpareAuthori,
  updateEnableApplySpare,
  updateEnableCheckSpare,
  updateEnableFeeAuthori,
  updateEnableApplyFee,
  updateEnableCheckFee,
  updateOrderBalanceStrategy,
} from '@/api/merchant'
import { ref } from 'vue'

// 批量更新开启或关闭工单配件权限加载
const updateEnableSpareAuthoriLoading = ref(false)

// 批量更新开启或关闭工单配件权限方法
const updateEnableSpareAuthoriFn = async (enableSpareAuthori: boolean, ids: Array<string>) => {
  updateEnableSpareAuthoriLoading.value = true
  const res = await updateEnableSpareAuthori(enableSpareAuthori, ids)
  updateEnableSpareAuthoriLoading.value = false
  return res.data as { code: number; data: object; message: string; success: boolean }
}

// 批量更新开启或关闭申请工单配件加载
const updateEnableApplySpareLoading = ref(false)

// 批量更新开启或关闭申请工单配件方法
const updateEnableApplySpareFn = async (enableSpare: boolean, factoryIds: Array<string>) => {
  updateEnableApplySpareLoading.value = true
  const res = await updateEnableApplySpare(enableSpare, factoryIds)
  updateEnableApplySpareLoading.value = false
  return res.data
}

// 批量更新开启或关闭审核工单配件加载
const updateEnableCheckSpareLoading = ref(false)

// 批量更新开启或关闭审核工单配件方法
const updateEnableCheckSpareFn = async (enableCheckSpare: boolean, factoryIds: Array<string>) => {
  updateEnableCheckSpareLoading.value = true
  const res = await updateEnableCheckSpare(enableCheckSpare, factoryIds)
  updateEnableCheckSpareLoading.value = false
  return res.data
}

// 批量更新开启或关闭工单费用权限加载
const updateEnableFeeAuthoriLoading = ref(false)

// 批量更新开启或关闭工单费用权限方法
const updateEnableFeeAuthoriFn = async (enableFeeAuthori: boolean, factoryIds: Array<string>) => {
  updateEnableFeeAuthoriLoading.value = true
  const res = await updateEnableFeeAuthori(enableFeeAuthori, factoryIds)
  updateEnableFeeAuthoriLoading.value = false
  return res.data as { code: number; data: object; message: string; success: boolean }
}

// 批量更新开启或关闭申请工单费用加载
const updateEnableApplyFeeLoading = ref(false)

// 批量更新开启或关闭申请工单费用方法
const updateEnableApplyFeeFn = async (enableFee: boolean, factoryIds: Array<string>) => {
  updateEnableApplyFeeLoading.value = true
  const res = await updateEnableApplyFee(enableFee, factoryIds)
  updateEnableApplyFeeLoading.value = false
  return res.data
}

// 批量更新开启或关闭审核工单费用加载
const updateEnableCheckFeeLoading = ref(false)

// 批量更新开启或关闭审核工单费用方法
const updateEnableCheckFeeFn = async (enableCheckFee: boolean, factoryIds: Array<string>) => {
  updateEnableCheckFeeLoading.value = true
  const res = await updateEnableCheckFee(enableCheckFee, factoryIds)
  updateEnableCheckFeeLoading.value = false
  return res.data
}

// 批量更新余额不足报单策略加载
const updateOrderBalanceStrategyLoading = ref(false)

// 批量更新余额不足报单策略方法
const updateOrderBalanceStrategyFn = async (orderBalanceStrategy: 1 | 2, ids: Array<string>) => {
  updateOrderBalanceStrategyLoading.value = true
  const res = await updateOrderBalanceStrategy(orderBalanceStrategy, ids)
  updateOrderBalanceStrategyLoading.value = false
  return res.data as { code: number; data: object; message: string; success: boolean }
}

export default {
  updateEnableApplyFeeLoading,
  updateEnableCheckFeeLoading,
  updateEnableCheckSpareLoading,
  updateEnableApplySpareLoading,
  updateEnableFeeAuthoriLoading,
  updateEnableSpareAuthoriLoading,
  updateOrderBalanceStrategyLoading,
  updateEnableApplyFeeFn,
  updateEnableCheckFeeFn,
  updateEnableCheckSpareFn,
  updateEnableApplySpareFn,
  updateEnableFeeAuthoriFn,
  updateEnableSpareAuthoriFn,
  updateOrderBalanceStrategyFn,
}
